package myalg.graphs.alg.dijkstra;

import myalg.graphs.Edge;
import myalg.graphs.Graph;
import myalg.graphs.Vertex;
import myalg.graphs.alg.BasicAlgorithm;

import java.util.*;

/**
 * @author Pavel Belevich
 *         Date: Jul 23, 2012
 *         Time: 3:10:34 PM
 */
public class Dijkstra extends BasicAlgorithm {
    
    private Graph graph;
    private Vertex start;
    private Map<Vertex, Double> d;
    private Map<Vertex, Vertex> p;

    private Queue<Vertex> q;
    private Collection<Vertex> u;

    public Dijkstra(Graph graph, Vertex start, Map<Vertex, Double> d, Map<Vertex, Vertex> p)   {
        this.graph = graph;
        this.start = start;
        this.d = d;
        this.p = p;
    }

    @Override
    public void run() {
        sleep(3000);
        for (Vertex v : this.graph.getVertices()) {
            this.d.put(v, Double.POSITIVE_INFINITY);
        }
        this.q = new PriorityQueue<Vertex>(0,new Comparator<Vertex>() {
            @Override
            public int compare(Vertex o1, Vertex o2) {
                return d.get(o1).compareTo(d.get(o2));
            }
        });
        this.q.addAll(this.graph.getVertices());
        this.d.put(this.start, 0.0);
        step();

        while (!q.isEmpty()) {
            Vertex u = q.poll(); //vertex in q with smallest distance in d - Start node in first case
            for (Edge e : u.getEdges()) {
                Vertex v = e.getAdjacent(u);
                
            }
        }
    }

}